1 //+-----------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // Description: This file is a common point of interop with the
6 // security Manager. It also stores an instance of
7 // security Manager such that we do not need to keep
8 // CoCreating it over and over.
11 // 2005/06/14 - Created the file
12 // 2007/09/20 - [....]
13 // Ported Windows->DevDiv. See SourcesHistory.txt.
15 //------------------------------------------------------------------------
17 #include "Precompiled.hxx"
18 #include "urlmoninterop.hxx"
19 #include "SecurityManagerSiteImpl.hxx"
23 #define MAXDWORD 0xffffffff
27 //initialize static variable
28 IInternetSecurityManager
*UrlmonInterop::s_pInternetSecurityManager
= NULL
;
29 IInternetSecurityMgrSite
*UrlmonInterop::s_pSecurityMgrSiteImpl
= NULL
;
33 //call this only when you are done using the securitymanager
34 HRESULT
UrlmonInterop::ReleaseSecurityManager()
36 ReleaseInterface(UrlmonInterop::s_pInternetSecurityManager
);
37 ReleaseInterface(UrlmonInterop::s_pSecurityMgrSiteImpl
);
41 // convenience functionality if you want to get an instance of this pointer
42 // the expectation is that the consumer of this interface calls release on the interface
43 // after he/she is done
44 HRESULT
UrlmonInterop::GetSecurityManager(__out_ecount_opt(1)IInternetSecurityManager
**ppInternetSecurityManager
)
47 // check for null pointer and send it back
48 if(ppInternetSecurityManager
== NULL
)
52 if(s_pInternetSecurityManager
== NULL
)
54 // cocreate the pointer to the COM interface we require
55 // CLSID for internet security managed "7b8a2d94-0ac9-11d1-896c-00c04Fb6bfc4"
56 // GUID for the interface we want to extract "79eac9ee-baf9-11ce-8c82-00aa004ba90b"
57 CKHR(CoCreateInstance(CLSID_InternetSecurityManager
,
58 NULL
, CLSCTX_INPROC_SERVER
,
59 IID_IInternetSecurityManager
,
60 (void **)&s_pInternetSecurityManager
));
62 *ppInternetSecurityManager
= s_pInternetSecurityManager
;
63 s_pInternetSecurityManager
->AddRef();
68 // This code takes the url action to invoke and calls it after it
69 // creates an instance of the InternetSecurityManager
70 HRESULT
UrlmonInterop::ProcessUrlActionWrapper(
72 __in_ecount(1) LPOLESTR pUrl
,
73 __in_ecount_opt(1)COleDocument
* pOleDoc
,
74 __out_ecount(1)BOOL
&fAllow
)
77 DWORD dwPolicy
= URLPOLICY_DISALLOW
;
78 IInternetSecurityManager
*pSecurityManager
= NULL
;
80 CKHR(GetSecurityManager(&pSecurityManager
));
82 UrlmonInterop::s_pSecurityMgrSiteImpl
= (IInternetSecurityMgrSite
*)new SecurityManagerSiteImpl(pOleDoc
);
83 // create an object and register it
84 CKHR(RegisterSecurityManagerSite());
86 // ProcessUrlAction will do the right thing based on call and registry settings
87 CKHR(pSecurityManager
->ProcessUrlAction(pUrl
,
95 //false if user clicked no true otherwise
96 fAllow
= (dwPolicy
== URLPOLICY_ALLOW
);
98 ReleaseInterface(pSecurityManager
);
103 HRESULT
UrlmonInterop::RegisterSecurityManagerSite()
106 CKHR(UrlmonInterop::s_pInternetSecurityManager
->SetSecuritySite((IInternetSecurityMgrSite
*)UrlmonInterop::s_pSecurityMgrSiteImpl
));